package com.etoak.config;

import cn.hutool.core.util.StrUtil;
import com.etoak.common.core.properties.ImageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

@Configuration
public class EtConfig implements WebFluxConfigurer {
    @Autowired
    ImageProperties imageProperties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println(imageProperties);
        /**
         * mapping="/pics/**
         */
        String mapping = imageProperties.getPrefix().endsWith(StrUtil.SLASH) ?
                imageProperties.getPrefix() + "**" :
                imageProperties.getPrefix() + "/**";
        //location="file:d:/upload/et2409/

        // imageProperties.getLocation() =====d:/upload/et2409
        String location = imageProperties.getLocation().endsWith(StrUtil.SLASH) ?
                "file:" + imageProperties.getLocation() :
                "file:" + imageProperties.getLocation() + StrUtil.SLASH;
        registry.addResourceHandler(mapping).addResourceLocations(location);;

    }
}
